//
//  YXYGroupNextTableViewCell.m
//  Topit
//
//  Created by dllo on 15/12/11.
//  Copyright © 2015年 YXY. All rights reserved.
//

#import "YXYGroupNextTableViewCell.h"

@implementation YXYGroupNextTableViewCell

- (void)dealloc {
    [_groupNextViewModel release];
    [_name release];
    [_myImage release];
    [_time release];
    [_idName release];
    [_content release];
    [_viewImage release];
    [_albumName release];
    [_number release];
    [_bio release];
    [super dealloc];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.name = [[UILabel alloc] initWithFrame:CGRectZero];
        self.name.font = [UIFont systemFontOfSize:12];
        [self addSubview:self.name];
        [_name release];
        
        self.myImage = [[UIImageView alloc] initWithFrame:CGRectZero];
        self.myImage.layer.cornerRadius = 15;
        self.myImage.clipsToBounds = YES;
        [self addSubview:self.myImage];
        [_myImage release];
        
        self.time = [[UILabel alloc] initWithFrame:CGRectZero];
        self.time.font = [UIFont systemFontOfSize:10];
        self.time.textColor = [UIColor grayColor];
        [self addSubview:self.time];
        [_time release];
        
        self.idName = [[UILabel alloc] initWithFrame:CGRectZero];
        self.idName.font = [UIFont systemFontOfSize:12];
        [self addSubview:self.idName];
        [_idName release];
        
        self.content = [[UILabel alloc] initWithFrame:CGRectZero];
        self.content.font = [UIFont systemFontOfSize:12];
        [self addSubview:self.content];
        [_content release];
        
        self.viewImage = [[UIImageView alloc] initWithFrame:CGRectZero];
        [self addSubview:self.viewImage];
        [_viewImage release];
        
        self.grayView = [[UIView alloc] initWithFrame:CGRectZero];
        self.grayView.backgroundColor = [UIColor grayColor];
        self.grayView.alpha = 0.8;
        [self addSubview:self.grayView];
        [_grayView release];
        
        self.albumName = [[UILabel alloc] initWithFrame:CGRectZero];
        self.albumName.textColor = [UIColor blackColor];
        self.albumName.textAlignment = 1;
        self.albumName.numberOfLines = 0;
        [self.grayView addSubview:self.albumName];
        [_albumName release];
        
        self.number = [[UILabel alloc] initWithFrame:CGRectZero];
        self.number.font = [UIFont systemFontOfSize:11];
        self.number.textAlignment = 1;
        
        self.number.textColor = [UIColor blackColor];
        [self.grayView addSubview:self.number];
        [_number release];
        
        self.bio = [[UILabel alloc] initWithFrame:CGRectZero];
        self.bio.font = [UIFont systemFontOfSize:11];
        self.bio.textAlignment = 1;
        self.bio.numberOfLines = 0;
        self.bio.textColor = [UIColor blackColor];
        [self.grayView addSubview:self.bio];
        [_bio release];
        
    }
    return self;
}

- (void)setGroupNextViewModel:(YXYGroupNextViewModel *)groupNextViewModel {
    if (_groupNextViewModel != groupNextViewModel) {
        [_groupNextViewModel release];
        _groupNextViewModel = [groupNextViewModel retain];
    }
    self.idName.text = groupNextViewModel.user[@"name"];
    [self.idName nightMode];
    
    [self.myImage sd_setImageWithURL:[NSURL URLWithString:groupNextViewModel.user[@"icon"][@"url"]]];
    [self.myImage nightMode];
    
    self.time.text = groupNextViewModel.last_ts;
    [self.time nightMode];
    
    self.name.text = groupNextViewModel.name;
    [self.name nightMode];
    
    self.content.text = groupNextViewModel.content;
    [self.content nightMode];
    
    [self.viewImage sd_setImageWithURL:[NSURL URLWithString:groupNextViewModel.album[@"icon"][@"url"]]];
    [self.viewImage nightMode];
    
    self.albumName.text = groupNextViewModel.album[@"name"];
    [self.albumName nightMode];
    
    self.number.text = [NSString stringWithFormat:@"%@%@", groupNextViewModel.album[@"onum"], @"张图片"];
    [self.number nightMode];
    
    self.bio.text = groupNextViewModel.album[@"bio"];
    [self.bio nightMode];
}

-(void)layoutSubviews {
    [super layoutSubviews];
    self.myImage.frame = CGRectMake(5, 5, 30, 30);
    self.idName.frame =  CGRectMake(self.myImage.right + 5, self.myImage.origin.y, 200, 15);
    self.time.frame = CGRectMake(self.idName.origin.x, self.idName.bottom + 5, 200, 15);
    self.name.frame = CGRectMake(self.myImage.origin.x, self.myImage.bottom + 5, self.width, 15);
    self.content.frame = CGRectMake(self.name.origin.x, self.name.bottom + 10, self.width, 15);
    self.viewImage.frame = CGRectMake(self.content.origin.x, self.content.bottom + 10, self.width / 2, self.width / 2);
    
    self.grayView.frame = CGRectMake(self.viewImage.right, self.viewImage.origin.y, self.viewImage.width, self.viewImage.height);
    self.albumName.frame = CGRectMake(0, 20, self.grayView.width - 5, 40);
    self.number.frame = CGRectMake(0, self.albumName.bottom + 10, self.albumName.width, 40);
    self.bio.frame = CGRectMake(0, self.number.bottom, self.number.width, 40);
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
